/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Principal.java
 *
 * Created on 04/09/2011, 11:33:41
 */
package lomext.gui;

import lomext.gui.utils.Mensagens;

/**
 *
 * @author Felipe
 */
public class Principal extends javax.swing.JFrame {
    Mensagens mensagem;
    boolean editorAberto;

    /** Creates new form Principal */
    public Principal() {
        initComponents();
        
        //Inicialização das variáveis da classe.
        mensagem = new Mensagens(this);
        editorAberto = false;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        barraPrincipal = new javax.swing.JToolBar();
        btnNovo = new javax.swing.JButton();
        slpPrincipal = new javax.swing.JScrollPane();
        menuPrincipal = new javax.swing.JMenuBar();
        menuArquivo = new javax.swing.JMenu();
        menuItemNovo = new javax.swing.JMenuItem();
        menuEditar = new javax.swing.JMenu();
        menuAjuda = new javax.swing.JMenu();
        menuItemAjuda = new javax.swing.JMenuItem();
        separador1 = new javax.swing.JPopupMenu.Separator();
        menuItemSobre = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(1024, 728));

        barraPrincipal.setRollover(true);

        btnNovo.setText("Novo");
        btnNovo.setFocusable(false);
        btnNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNovoActionPerformed(evt);
            }
        });
        barraPrincipal.add(btnNovo);

        menuArquivo.setText("Arquivo");

        menuItemNovo.setText("Novo");
        menuItemNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemNovoActionPerformed(evt);
            }
        });
        menuArquivo.add(menuItemNovo);

        menuPrincipal.add(menuArquivo);

        menuEditar.setText("Editar");
        menuPrincipal.add(menuEditar);

        menuAjuda.setText("Ajudar");

        menuItemAjuda.setText("Ajuda");
        menuAjuda.add(menuItemAjuda);
        menuAjuda.add(separador1);

        menuItemSobre.setText("Sobre");
        menuAjuda.add(menuItemSobre);

        menuPrincipal.add(menuAjuda);

        setJMenuBar(menuPrincipal);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(barraPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, 1024, Short.MAX_VALUE)
            .addComponent(slpPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, 1024, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(barraPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(slpPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, 676, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNovoActionPerformed
        novoEditor();       
    }//GEN-LAST:event_btnNovoActionPerformed

private void menuItemNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemNovoActionPerformed
        novoEditor();
}//GEN-LAST:event_menuItemNovoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Principal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToolBar barraPrincipal;
    private javax.swing.JButton btnNovo;
    private javax.swing.JMenu menuAjuda;
    private javax.swing.JMenu menuArquivo;
    private javax.swing.JMenu menuEditar;
    private javax.swing.JMenuItem menuItemAjuda;
    private javax.swing.JMenuItem menuItemNovo;
    private javax.swing.JMenuItem menuItemSobre;
    private javax.swing.JMenuBar menuPrincipal;
    private javax.swing.JPopupMenu.Separator separador1;
    private javax.swing.JScrollPane slpPrincipal;
    // End of variables declaration//GEN-END:variables

    private void novoEditor() {
        boolean abrirNovo = true;
        if (editorAberto){
            abrirNovo = mensagem.Questao("Já existe um projeto aberto, deseja criar um novo?");
        }
        
        if (abrirNovo){    
            Editor editorNovo = new Editor();
            slpPrincipal.setViewportView(editorNovo);
            editorAberto = true;
        }
    }
}
